/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.scene.web;

import com.lczyfz.istep.common.config.Global;
import com.lczyfz.istep.common.constants.DelFlag;
import com.lczyfz.istep.common.constants.SceneConstants;
import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.utils.CheckUtils;
import com.lczyfz.istep.common.utils.IdGen;
import com.lczyfz.istep.common.utils.JsonModel;
import com.lczyfz.istep.common.utils.StringUtils;
import com.lczyfz.istep.common.web.BaseController;
import com.lczyfz.istep.modules.resource.service.ResourceCoursewareService;
import com.lczyfz.istep.modules.scene.entity.*;
import com.lczyfz.istep.modules.scene.service.*;
import com.lczyfz.istep.modules.sys.service.SystemService;
import org.activiti.engine.impl.util.json.JSONArray;
import org.activiti.engine.impl.util.json.JSONObject;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * CTF实验环境Controller
 * @author dh
 * @version 2017-05-15
 */
@Controller
@RequestMapping(value = "${adminPath}/scene/sceneCtfEnvironment")
public class SceneCtfEnvironmentController extends BaseController {

	@Autowired
	private SceneCtfEnvironmentService sceneCtfEnvironmentService;
	@Autowired
	private SystemService systemService;
	@Autowired
	private SceneNetworkService sceneNetworkService;
	@Autowired
	private SceneRouterService sceneRouterService;
	@Autowired
	private SceneSecurityGroupService sceneSecurityGroupService;
	@Autowired
	private SceneSecurityGroupRuleService sceneSecurityGroupRuleService;
	@Autowired
	private SceneSubnetService sceneSubnetService;
	@Autowired
	private SceneVmTemplateService sceneVmTemplateService;
	@Autowired
	private SceneVmTypeService sceneVmTypeService;
	@Autowired
	private ScenePortService scenePortService;
	@Autowired
	private SceneEnvironmentInstanceService sceneEnvironmentInstanceService;
	@Autowired
	private ResourceCoursewareService resourceCoursewareService;

	@ModelAttribute
	public SceneCtfEnvironment get(@RequestParam(required=false) String id) {
		SceneCtfEnvironment entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = sceneCtfEnvironmentService.get(id);
		}
		if (entity == null){
			entity = new SceneCtfEnvironment();
		}
		return entity;
	}
	
	@RequiresPermissions("scene:sceneCtfEnvironment:view")
	@RequestMapping(value = {"list", ""})
	public String list(SceneCtfEnvironment sceneCtfEnvironment, HttpServletRequest request, HttpServletResponse response, Model model) {

		if(systemService.isSuperAdmin())
		{
			model.addAttribute("isSuperAdmin", "true");

		}
		else
		{
			model.addAttribute("isSuperAdmin", "false");
		}
		Page<SceneCtfEnvironment> page = sceneCtfEnvironmentService.findPage(new Page<SceneCtfEnvironment>(request, response), sceneCtfEnvironment);
		model.addAttribute("page", page);
		return "modules/scene/sceneCtfEnvironmentList";
	}

	@RequiresPermissions("scene:sceneCtfEnvironment:view")
	@RequestMapping(value = "form")
	public String form(SceneCtfEnvironment sceneCtfEnvironment, Model model) {
		if(systemService.isSuperAdmin())
		{
			logger.debug("dingh===true");
			model.addAttribute("isSuperAdmin", "true");
		}else {
			model.addAttribute("isSuperAdmin", "false");
			logger.debug("dingh===false");
		}
		model.addAttribute("sceneCtfEnvironment", sceneCtfEnvironment);
		return "modules/scene/sceneCtfEnvironmentForm";
	}

	@RequiresPermissions("scene:sceneCtfEnvironment:edit")
	@RequestMapping(value = "save")
	public String save(SceneCtfEnvironment sceneCtfEnvironment, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, sceneCtfEnvironment)){
			return form(sceneCtfEnvironment, model);
		}
		sceneCtfEnvironmentService.save(sceneCtfEnvironment);
		addMessage(redirectAttributes, "保存CTF实验环境成功");
		return "redirect:"+Global.getAdminPath()+"/scene/sceneCtfEnvironment/?repage";
	}
	
	@RequiresPermissions("scene:sceneCtfEnvironment:edit")
	@RequestMapping(value = "delete")
	public String delete(SceneCtfEnvironment sceneCtfEnvironment, RedirectAttributes redirectAttributes) {
		sceneCtfEnvironmentService.delete(sceneCtfEnvironment);
		sceneCtfEnvironmentService.evmRelateDelete(sceneCtfEnvironment);
		addMessage(redirectAttributes, "删除CTF实验环境成功");
		return "redirect:"+Global.getAdminPath()+"/scene/sceneCtfEnvironment/?repage";
	}

	@RequiresPermissions("scene:sceneCtfEnvironment:view")
	@RequestMapping(value = "topology")
	public String topology(SceneCtfEnvironment sceneCtfEnvironment, Model model, RedirectAttributes redirectAttributes) {

		logger.debug("dingh===topology123");
		SceneCtfEnvironment temp=sceneCtfEnvironmentService.findCtfEnvironmentByName(sceneCtfEnvironment.getCtfEnvironmentName(), DelFlag.DEL_FLAG_NORMAL);
		if(sceneCtfEnvironmentService.get(sceneCtfEnvironment)==null)
		{
			if(temp!=null)
			{
				addMessage(redirectAttributes, "保存Ctf实验环境失败，该实验环境已存在");
				return "redirect:"+Global.getAdminPath()+"/scene/sceneCtfEnvironment/?repage";

			}
		}else {
			if(temp!=null&&!temp.getId().equals(sceneCtfEnvironment.getId()))
			{
				addMessage(redirectAttributes, "修改Ctf实验环境失败，该实验环境已存在");
				return "redirect:"+Global.getAdminPath()+"/scene/sceneCtfEnvironment/?repage";

			}
		}

		if(sceneCtfEnvironment.getIncreaseTimeAllow().equals("1"))
		{
			sceneCtfEnvironment.setIncreaseNumber(null);
			sceneCtfEnvironment.setIncreaseTime(null);
		}
		if(sceneCtfEnvironment.getAnswerType().equals("1"))
		{
			sceneCtfEnvironment.setFixedAnswer(null);
		}else {
			sceneCtfEnvironment.setAccount(null);
			sceneCtfEnvironment.setPassword(null);
		}
		if(sceneCtfEnvironment.getCtfType().equals("0"))
		{
			sceneCtfEnvironment.setPort(null);
			sceneCtfEnvironment.setIp(null);
		}

		logger.debug("saveTopology===111" + sceneCtfEnvironment.getCtfEnvironmentName());
		if(sceneCtfEnvironment.getTopologyXml()!=null&&!sceneCtfEnvironment.getTopologyXml().equals("")) {
			String str = sceneCtfEnvironment.getTopologyXml().replace("\"", "\\\"");
			sceneCtfEnvironment.setTopologyXml(str);
		}
		model.addAttribute("sceneCtfEnvironment", sceneCtfEnvironment);
		logger.debug("saveTopology===1113a");

		return "modules/scene/sceneCtfEnvironmentTopology";
	}
	public String getDate(String str)
	{
		String result="";
		str="["+str+"]";

		logger.debug("dingh===str="+str);
		try
		{
			JSONArray jsonArray = new JSONArray(str);
			for (int i=0; i < jsonArray.length(); i++)    {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				String title = jsonObject.getString("title");
				String type = jsonObject.getString("type");
				String data = jsonObject.getString("data");
				if(type.equals("select"))
				{
					String selected = jsonObject.getString("selected");
					result=selected;

				}else if(type.equals("input"))
				{
					result=data;
				}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return result;
	}

	@ResponseBody
	@RequestMapping(value = "saveTopology")
	public JsonModel saveTopology(SceneCtfEnvironment sceneCtfEnvironment, Model model,String topologyXml) {
		InputStream is = null;
		JsonModel jsonModel=new JsonModel();

		topologyXml= StringEscapeUtils.unescapeXml(topologyXml);

		logger.debug("反转义HTMLsss:" +topologyXml);
		logger.debug("sceneEnvironmentId:" + sceneCtfEnvironment.getId());
		SceneCtfEnvironment temp=sceneCtfEnvironmentService.get(sceneCtfEnvironment);
		if(temp!=null&&temp.getId()!=null)
		{
			//修改
			logger.debug("dingh===修改ctf实验环境");
			if(temp.getTopologyXml().equals(topologyXml))
			{
				sceneCtfEnvironmentService.save(sceneCtfEnvironment);
				return null;
			}else {
				sceneCtfEnvironmentService.evmRelateDelete(temp);
			}
		}
		List<Mode> modeList=new ArrayList<>();
		List<Line> lineList=new ArrayList<>();

		try {
			is = new ByteArrayInputStream(topologyXml.getBytes("gbk"));
			Reader read = new InputStreamReader(is,"gbk");
			SAXReader reader = new SAXReader();
			Document document = reader.read(read);
			Element root = document.getRootElement();
			List<Element> childElements = root.elements();
			for (Element child : childElements) {
				logger.debug("child:" + child.getName());
				if(child.getName().equals("mode"))
				{
					Mode mode=new Mode();
					mode.setId(child.attributeValue("id"));
					mode.setChild(child.attributeValue("child"));
					mode.setBackImgSrc(child.attributeValue("backImgSrc"));
					mode.setTitle(child.attributeValue("title"));
					mode.setTop(child.attributeValue("top"));
					mode.setLeft(child.attributeValue("left"));
					mode.setWidth(child.attributeValue("width"));
					mode.setHeight(child.attributeValue("height"));
					if(child.attributeValue("backImgSrc").contains("baseMode1.png"))
					{
						String attri=child.attributeValue("attr_prop_attri1");
						String str=getDate(attri);
						if(str==null||str.equals(""))
						{
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("请选择外部网络");
							return jsonModel;
						}
						mode.setType(1);


					}else if(child.attributeValue("backImgSrc").contains("baseMode2.png"))
					{
						String routerName=child.attributeValue("attr_prop_attri1");
						String routerIp=child.attributeValue("attr_prop_attri2");
						String str1=getDate(routerName);
						String str2=getDate(routerIp);

						if(str1==null||str1.equals(""))
						{
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("路由名称不能为空");
							return jsonModel;
						}else {
							if (CheckUtils.isContainChinese(str1)) {
								jsonModel.setSuccess(false);
								jsonModel.setDataObj("路由名称不能包含中文");
								return jsonModel;

							}
						}

						if(str2==null||str2.equals("")) {
//							jsonModel.setSuccess(false);
//							jsonModel.setDataObj("路由IP不能为空");
//							return jsonModel;
						}else {
							mode.setVmIp(str2);

							if(!CheckUtils.isIp(str2))
							{
								jsonModel.setSuccess(false);
								jsonModel.setDataObj("路由IP不合法");
								return jsonModel;

							}
						}
						mode.setType(2);

					}else if(child.attributeValue("backImgSrc").contains("baseMode3.png")||child.attributeValue("backImgSrc").contains("baseMode6.png"))
					{
						String networtName=child.attributeValue("attr_prop_attri1");
						String subnetName=child.attributeValue("attr_prop_attri1");
						String cidr=child.attributeValue("attr_prop_attri2");
						String ipVersion=child.attributeValue("attr_prop_attri3");

						String str1=getDate(networtName);
						String str2=getDate(subnetName);
						String str3=getDate(cidr);
						String str4=getDate(ipVersion);

						if(str1==null||str1.equals(""))
						{
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("交换机名称不能为空");
							return jsonModel;
						}else {
							if (CheckUtils.isContainChinese(str1)) {
								jsonModel.setSuccess(false);
								jsonModel.setDataObj("交换机名称不能包含中文");
								return jsonModel;

							}
						}
						if(str2==null||str2.equals(""))
						{
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("交换机名称不能为空");
							return jsonModel;
						}
						if(str3==null||str3.equals(""))
						{
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("网络地址不能为空");
							return jsonModel;
						}else {
							mode.setCidr(str3);

						}
						if(str4==null||str4.equals(""))
						{
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("IP版本不能为空");
							return jsonModel;
						}
						mode.setType(3);

					}else if(child.attributeValue("backImgSrc").contains("baseMode4.png"))
					{
						//虚拟机
						String vmName=child.attributeValue("attr_prop_attri1");
						String vmTemplate=child.attributeValue("attr_prop_attri2");
						String isOperateMachine=child.attributeValue("attr_prop_attri3");
						String vmIp=child.attributeValue("attr_prop_attri4");

						String str1=getDate(vmName);
						String str2=getDate(vmTemplate);
						String str3=getDate(isOperateMachine);
						String str4=getDate(vmIp);

						if(str1==null||str1.equals("")) {
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("虚拟机名称不能为空");
							return jsonModel;
						}
						if(str4==null||str4.equals("")) {
				/**930修改			jsonModel.setSuccess(false);
							jsonModel.setDataObj("固定IP不能为空");
							return jsonModel;*/
						}else {
							mode.setVmIp(str4);

							if(!CheckUtils.isIp(str4))
							{
								jsonModel.setSuccess(false);
								jsonModel.setDataObj("虚拟机IP不合法");
								return jsonModel;

							}
						}
						if(str2==null||str2.equals(""))
						{
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("请选择虚拟机模板");
							return jsonModel;
						}
						mode.setType(4);

					}else if(child.attributeValue("backImgSrc").contains("baseMode5.png"))
					{
						//防火墙
						String firewallName=child.attributeValue("attr_prop_attri1");
						String firewallPolicyName=child.attributeValue("attr_prop_attri1");

						String str1=getDate(firewallName);
						String str2=getDate(firewallPolicyName);


						if(str1==null||str1.equals("")) {
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("防火墙名称不能为空");
							return jsonModel;
						}else {
							if (CheckUtils.isContainChinese(str1)) {
								jsonModel.setSuccess(false);
								jsonModel.setDataObj("防火墙名称不能包含中文");
								return jsonModel;

							}
						}
						if(str2==null||str2.equals("")) {
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("防火墙名称不能为空");
							return jsonModel;
						}
						mode.setType(5);


					}
					modeList.add(mode);


				}else if(child.getName().equals("line")){

					Line line=new Line();
					line.setId(child.attributeValue("id"));
					line.setChild(child.attributeValue("child"));
					line.setPath(child.attributeValue("path"));
					lineList.add(line);
				}

			}
			for(int i=0;i<lineList.size();i++)
			{
				Line line=lineList.get(i);

				String path=line.getPath();//path: M 298 298 L 534 112
				String[] local=path.split(" ");
				int left1=Integer.parseInt(local[1]);
				int top1=Integer.parseInt(local[2]);

				int left2=Integer.parseInt(local[4]);
				int top2=Integer.parseInt(local[5]);
				logger.debug("line:"+left1+" "+top1+" "+left2+" "+top2+" ");

				String modeId1="",modeId2="";
				int index1=0,index2=0;
				Mode relateMode1=null,relateMode2=null;
				boolean findModeA=false;
				boolean findModeB=false;

				for(int j=0;j<modeList.size();j++)
				{

					Mode mode=modeList.get(j);
					int modeLeft=Integer.parseInt(mode.getLeft());
					int modeTop=Integer.parseInt(mode.getTop());
					logger.debug("mode:"+modeLeft+" "+modeTop);

					if((modeLeft-5)<=left1&&left1<+(modeLeft+50+5)&&(modeTop-5)<=top1&&top1<+(modeTop+50+5))
					{
						index1=j;
						modeId1=modeList.get(j).getId();
						relateMode1=modeList.get(j);
						logger.debug("找到modeA="+modeList.get(j).getId());
						findModeA=true;
					}
					if((modeLeft-5)<=left2&&left2<+(modeLeft+50+5)&&(modeTop-5)<=top2&&top2<+(modeTop+50+5))
					{
						index2=j;
						modeId2=modeList.get(j).getId();
						relateMode2=modeList.get(j);
						logger.debug("找到modeB="+modeList.get(j).getId());
						findModeB=true;

					}
				}
				if(findModeA==false||findModeB==false)
				{
					jsonModel.setSuccess(false);
					jsonModel.setDataObj("连线两端未都连接，请检查");
					return jsonModel;
				}
				modeList.get(index1).setRelateModeId(modeId2);
				modeList.get(index2).setRelateModeId(modeId1);
				int type1=modeList.get(index1).getType();
				int type2=modeList.get(index2).getType();
				switch (type1)
				{
					case 1:
						modeList.get(index1).setRelateModeRight(relateMode2);
						modeList.get(index2).setRelateModeLeft(relateMode1);

						break;
					case 2:
						switch (type2)
						{
							case 1:
								modeList.get(index1).setRelateModeLeft(relateMode2);
								modeList.get(index2).setRelateModeRight(relateMode1);
								break;
							case 2:
								break;
							case 3:
								modeList.get(index1).setRelateModeRight(relateMode2);
								modeList.get(index2).setRelateModeLeft(relateMode1);
								break;
							case 4:
								break;
							case 5:
								modeList.get(index1).setRelateModeLeft(relateMode2);
								modeList.get(index2).setRelateModeRight(relateMode1);
								break;
						}
						break;
					case 3:
						switch (type2)
						{
							case 1:
								break;
							case 2:
								modeList.get(index1).setRelateModeLeft(relateMode2);
								modeList.get(index2).setRelateModeRight(relateMode1);
								break;
							case 3:
								break;
							case 4:
								modeList.get(index1).setRelateModeRight(relateMode2);
								modeList.get(index2).setRelateModeLeft(relateMode1);
								break;
							case 5:
								modeList.get(index1).setRelateModeRight(relateMode2);
								modeList.get(index2).setRelateModeLeft(relateMode1);
								break;
						}
						break;
					case 4:
						modeList.get(index1).setRelateModeLeft(relateMode2);
						modeList.get(index2).setRelateModeRight(relateMode1);
						break;
					case 5:
						switch (type2)
						{
							case 1:
								modeList.get(index1).setRelateModeLeft(relateMode2);
								modeList.get(index2).setRelateModeRight(relateMode1);
								break;
							case 2:
								modeList.get(index1).setRelateModeRight(relateMode2);
								modeList.get(index2).setRelateModeLeft(relateMode1);
								break;
							case 3:
								break;
							case 4:
								break;
							case 5:
								break;
						}
						break;
				}

			}
/**	930修改		for(int i=0; i<modeList.size();i++)
			{
				if(modeList.get(i).getType()==4)
				{
					if(modeList.get(i).getRelateModeLeft()==null)
					{
						jsonModel.setSuccess(false);
						jsonModel.setDataObj("虚拟机必须连接交换机");
						return jsonModel;
					}else{
						try{
							if(!CheckUtils.isIpInRange(modeList.get(i).getVmIp(),modeList.get(i).getRelateModeLeft().getCidr()))
							{
								jsonModel.setSuccess(false);
								jsonModel.setDataObj("虚拟机IP不在交换机网络地址内");
								return jsonModel;
							}
						}catch (Exception e)
						{
							jsonModel.setSuccess(false);
							jsonModel.setDataObj("虚拟机IP不在交换机网络地址内，请检查网段是否正确");
							return jsonModel;
						}
					}
				}else
				{
					continue;
				}
			}
*/
			//111111=========================================
			logger.debug("dingh===123123111111111");
			modeList=new ArrayList<>();
			lineList=new ArrayList<>();
			sceneCtfEnvironment.setTopologyXml(topologyXml);
			sceneCtfEnvironmentService.save(sceneCtfEnvironment);

			for (Element child : childElements) {
				logger.debug("child:" + child.getName());



				if(child.getName().equals("mode"))
				{
					Mode mode=new Mode();
					mode.setId(child.attributeValue("id"));
					mode.setChild(child.attributeValue("child"));
					mode.setBackImgSrc(child.attributeValue("backImgSrc"));
					mode.setTitle(child.attributeValue("title"));
					mode.setTop(child.attributeValue("top"));
					mode.setLeft(child.attributeValue("left"));
					mode.setWidth(child.attributeValue("width"));
					mode.setHeight(child.attributeValue("height"));

					if(child.attributeValue("backImgSrc").contains("baseMode1.png"))
					{
						mode.setType(1);
						String attri=child.attributeValue("attr_prop_attri1");
						String str=getDate(attri);
						if(str!=null&&!str.equals(""))
						{

							//外部网络
							mode.setPublicNetwork(str);
							logger.debug("dingh===setAttr_prop_外部网络:" + str);
						}


					}else if(child.attributeValue("backImgSrc").contains("baseMode2.png"))
					{
						mode.setType(2);
						String routerName=child.attributeValue("attr_prop_attri1");
						String routerIp=child.attributeValue("attr_prop_attri2");
						String str1=getDate(routerName);
						String str2=getDate(routerIp);

						if(str1!=null&&!str1.equals(""))
						{
							mode.setRouterName(str1);
							SceneRouter sceneRouter=new SceneRouter();
							sceneRouter.setRouterName(str1);
							sceneRouterService.save(sceneRouter);
							mode.setEnvId(sceneRouter.getId());
						}
						mode.setRouterIp(str2);
						logger.debug("dingh===新建路由id:" + mode.getEnvId());
						logger.debug("dingh===routerName:" + str1);



					}else if(child.attributeValue("backImgSrc").contains("baseMode3.png")||child.attributeValue("backImgSrc").contains("baseMode6.png"))
					{
						mode.setType(3);
						String networtName=child.attributeValue("attr_prop_attri1");
						String subnetName=child.attributeValue("attr_prop_attri1");
						String cidr=child.attributeValue("attr_prop_attri2");
						String ipVersion=child.attributeValue("attr_prop_attri3");

						String str1=getDate(networtName);
						String str2=getDate(subnetName);
						String str3=getDate(cidr);
						String str4=getDate(ipVersion);

						if(str1!=null&&!str1.equals(""))
						{
							mode.setNetwortName(str1);
							logger.debug("dingh===networtName:" + str1);
						}
						if(str2!=null&&!str2.equals(""))
						{
							mode.setSubnetName(str2);
							logger.debug("dingh===subnetName:" + str2);
						}
						if(str3!=null&&!str3.equals(""))
						{
							mode.setCidr(str3);
							logger.debug("dingh===cidr:" +str3);
						}
						if(str4!=null&&!str4.equals(""))
						{
							mode.setIpVersion(str4);
							logger.debug("dingh===ipVersion:" + str4);
						}
						SceneNetwork sceneNetwork=new SceneNetwork();
						sceneNetwork.setNetworkName(mode.getNetwortName());
						sceneNetwork.setType(SceneConstants.networkTypeNormal);

						sceneNetworkService.save(sceneNetwork);

						SceneSubnet sceneSubnet = new SceneSubnet();
						sceneSubnet.setSubnetName(mode.getSubnetName());
						sceneSubnet.setIpVersion(mode.getIpVersion());
						sceneSubnet.setCidr(mode.getCidr());
						sceneSubnet.setNetworkId(sceneNetwork.getId());
						sceneSubnetService.save(sceneSubnet);

						mode.setEnvId(sceneNetwork.getId());
						logger.debug("dingh===网络id:[{}],子网id:[{}]",sceneNetwork.getId(),sceneSubnet.getId());


					}else if(child.attributeValue("backImgSrc").contains("baseMode4.png"))
					{
						mode.setType(4);

						//虚拟机
						String vmName=child.attributeValue("attr_prop_attri1");
						String vmTemplate=child.attributeValue("attr_prop_attri2");
						String isOperateMachine=child.attributeValue("attr_prop_attri3");
						String vmIp=child.attributeValue("attr_prop_attri4");

						String str1=getDate(vmName);
						String str2=getDate(vmTemplate);
						String str3=getDate(isOperateMachine);
						String str4=getDate(vmIp);

						if(str1!=null&&!str1.equals("")) {
							logger.debug("dingh===vmName:" + str1);
							mode.setVmName(str1);
						}
						if(str4!=null&&!str4.equals("")) {
							logger.debug("dingh===vmIp:" + str4);
							mode.setVmIp(str4);
						}
						if(str2!=null&&!str2.equals(""))
						{
							logger.debug("dingh===attr_prop_虚拟机:" + str2);
							mode.setVmTemplate(str2);
							mode.setEnvId(str2);
						}
						if(str3!=null&&!str3.equals(""))
						{
							logger.debug("dingh===attr_prop_虚拟机:" + str3);
							mode.setIsOperateMachine(str3);
						}

					}else if(child.attributeValue("backImgSrc").contains("baseMode5.png"))
					{
						mode.setType(5);

						//防火墙
						String firewallName=child.attributeValue("attr_prop_attri1");
						String firewallPolicyName=child.attributeValue("attr_prop_attri1");

						String str1=getDate(firewallName);
						String str2=getDate(firewallPolicyName);

						if(str1!=null&&!str1.equals("")) {
							logger.debug("dingh===firewallName:" + str1);
							mode.setFirewallName(str1);
						}
						if(str2!=null&&!str2.equals("")) {
							logger.debug("dingh===firewallPolicyName:" + str2);
							mode.setFirewallPolicyName(str2);
						}
						SceneFirewall sceneFirewall=new SceneFirewall();
						String firewallId= IdGen.uuid();
						sceneFirewall.setId(firewallId);
						sceneFirewall.setFirewallName(mode.getFirewallName());
						sceneFirewall.setFirewallPolicyName(mode.getFirewallPolicyName());
						sceneRouterService.firewallInsert(sceneFirewall);
						mode.setEnvId(firewallId);
					}
					modeList.add(mode);

				}else if(child.getName().equals("line")){

					Line line=new Line();
					line.setId(child.attributeValue("id"));
					line.setChild(child.attributeValue("child"));
					line.setPath(child.attributeValue("path"));
					lineList.add(line);
				}

			}
			logger.debug("size:" + modeList.size());
			logger.debug("size:" + lineList.size());

			for(int i=0;i<modeList.size();i++)
			{
				logger.debug("mode:"+i+" " + modeList.get(i).getLeft()+" "+ modeList.get(i).getTop());

			}
			for(int i=0;i<lineList.size();i++)
			{
				Line line=lineList.get(i);

				String path=line.getPath();//path: M 298 298 L 534 112
				String[] local=path.split(" ");
				int left1=Integer.parseInt(local[1]);
				int top1=Integer.parseInt(local[2]);

				int left2=Integer.parseInt(local[4]);
				int top2=Integer.parseInt(local[5]);
				logger.debug("line:"+left1+" "+top1+" "+left2+" "+top2+" ");

				String modeId1="",modeId2="";
				int index1=0,index2=0;
				Mode relateMode1=null,relateMode2=null;
				boolean findModeA=false;
				boolean findModeB=false;
				for(int j=0;j<modeList.size();j++)
				{

					Mode mode=modeList.get(j);
					int modeLeft=Integer.parseInt(mode.getLeft());
					int modeTop=Integer.parseInt(mode.getTop());
					logger.debug("mode:"+modeLeft+" "+modeTop);

					if((modeLeft-5)<=left1&&left1<+(modeLeft+50+5)&&(modeTop-5)<=top1&&top1<+(modeTop+50+5))
					{
						index1=j;
						modeId1=modeList.get(j).getId();
						relateMode1=modeList.get(j);
						logger.debug("找到modeA="+modeList.get(j).getId());
						findModeA=true;

					}
					if((modeLeft-5)<=left2&&left2<+(modeLeft+50+5)&&(modeTop-5)<=top2&&top2<+(modeTop+50+5))
					{
						index2=j;
						modeId2=modeList.get(j).getId();
						relateMode2=modeList.get(j);
						logger.debug("找到modeB="+modeList.get(j).getId());
						findModeB=true;

					}
				}
				int type1=modeList.get(index1).getType();
				int type2=modeList.get(index2).getType();
				if(modeList.get(index1).getList()==null)
				{
					List<Mode> list=new ArrayList<Mode>();
					list.add(modeList.get(index2));
					modeList.get(index1).setList(list);
				}else{
					modeList.get(index1).getList().add(modeList.get(index2));
				}
				if(modeList.get(index2).getList()==null)
				{
					List<Mode> list=new ArrayList<Mode>();
					list.add(modeList.get(index1));
					modeList.get(index2).setList(list);
				}else{
					modeList.get(index2).getList().add(modeList.get(index1));
				}
				if(type1==2&&type2==2)
				{
					SceneNetwork sceneNetwork=new SceneNetwork();
					sceneNetwork.setNetworkName(modeList.get(index1).getRouterName()+"-"+modeList.get(index2).getRouterName());
					sceneNetwork.setType(SceneConstants.networkTypeVirtual);
					sceneNetworkService.save(sceneNetwork);
					sceneCtfEnvironmentService.evmNetworkInsert(sceneCtfEnvironment.getId(), sceneNetwork.getId());

					modeList.get(index1).setRouterNetworkId(sceneNetwork.getId());
					modeList.get(index2).setRouterNetworkId(sceneNetwork.getId());
				}

//				modeList.get(index1).setRelateModeId(modeId2);
//				modeList.get(index2).setRelateModeId(modeId1);
//				int type1=modeList.get(index1).getType();
//				int type2=modeList.get(index2).getType();
//				switch (type1)
//				{
//					case 1:
//						modeList.get(index1).setRelateModeRight(relateMode2);
//						modeList.get(index2).setRelateModeLeft(relateMode1);
//
//						break;
//					case 2:
//						switch (type2)
//						{
//							case 1:
//								modeList.get(index1).setRelateModeLeft(relateMode2);
//								modeList.get(index2).setRelateModeRight(relateMode1);
//								break;
//							case 2:
//								SceneNetwork sceneNetwork=new SceneNetwork();
//								sceneNetwork.setNetworkName(modeList.get(index1).getRouterName()+"-"+modeList.get(index2).getRouterName());
//								sceneNetwork.setType(SceneConstants.networkTypeVirtual);
//								sceneNetworkService.save(sceneNetwork);
//								sceneCtfEnvironmentService.evmNetworkInsert(sceneCtfEnvironment.getId(), sceneNetwork.getId());
//
//								modeList.get(index1).setRouterNetworkId(sceneNetwork.getId());
//								modeList.get(index2).setRouterNetworkId(sceneNetwork.getId());
//
//								modeList.get(index1).setRelateModeLeft(relateMode2);
//								modeList.get(index2).setRelateModeLeft(relateMode1);
//								break;
//							case 3:
//								modeList.get(index1).setRelateModeRight(relateMode2);
//								modeList.get(index2).setRelateModeLeft(relateMode1);
//								break;
//							case 4:
//								break;
//							case 5:
//								modeList.get(index1).setRelateModeLeft(relateMode2);
//								modeList.get(index2).setRelateModeRight(relateMode1);
//								break;
//						}
//						break;
//					case 3:
//						switch (type2)
//						{
//							case 1:
//								break;
//							case 2:
//								modeList.get(index1).setRelateModeLeft(relateMode2);
//								modeList.get(index2).setRelateModeRight(relateMode1);
//								break;
//							case 3:
//								break;
//							case 4:
//								modeList.get(index1).setRelateModeRight(relateMode2);
//								modeList.get(index2).setRelateModeLeft(relateMode1);
//								break;
//							case 5:
//								modeList.get(index1).setRelateModeRight(relateMode2);
//								modeList.get(index2).setRelateModeLeft(relateMode1);
//								break;
//						}
//						break;
//					case 4:
//						modeList.get(index1).setRelateModeLeft(relateMode2);
//						modeList.get(index2).setRelateModeRight(relateMode1);
//						break;
//					case 5:
//						switch (type2)
//						{
//							case 1:
//								modeList.get(index1).setRelateModeLeft(relateMode2);
//								modeList.get(index2).setRelateModeRight(relateMode1);
//								break;
//							case 2:
//								modeList.get(index1).setRelateModeRight(relateMode2);
//								modeList.get(index2).setRelateModeLeft(relateMode1);
//								break;
//							case 3:
//								break;
//							case 4:
//								break;
//							case 5:
//								break;
//						}
//						break;
//				}

				logger.debug("line-mode:"+modeId1+" "+modeId2);

			}

		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (DocumentException e) {
			e.printStackTrace();
		}


		for(int i=0; i<modeList.size();i++)
		{
			switch (modeList.get(i).getType())
			{
				case 1:

					break;
				case 2:
					logger.debug("dingh===case2:" + modeList.get(i).getEnvId());
//					SceneNetwork sceneNetwork=new SceneNetwork();
//					if(modeList.get(i).getRelateModeLeft()!=null&&modeList.get(i).getRelateModeLeft().getType()==1)
//					{
//						logger.debug("dingh===添加网关:" + modeList.get(i).getRelateModeLeft().getPublicNetwork());
//						SceneRouter sceneRouter=sceneRouterService.get(modeList.get(i).getEnvId());
//						sceneRouter.setNetworkId(modeList.get(i).getRelateModeLeft().getPublicNetwork());
//						sceneRouterService.save(sceneRouter);
//					}
//					if(modeList.get(i).getRelateModeLeft()!=null&&modeList.get(i).getRelateModeLeft().getType()==2)
//					{
//
//						SceneSubnet sceneSubnet = new SceneSubnet();
//						sceneSubnet.setSubnetName("snet-"+modeList.get(i).getRouterName());
//						sceneSubnet.setIpVersion("4");
//						String ip=modeList.get(i).getRouterIp();
//						logger.debug("dingh===ip:" + ip);
//						String cidr=ip.substring(0, ip.lastIndexOf("."))+".0/24";
//						sceneSubnet.setCidr(cidr);
//						sceneSubnet.setNetworkId(modeList.get(i).getRouterNetworkId());
//						sceneSubnetService.save(sceneSubnet);
//
//						//保存端口
//						ScenePort scenePort=new ScenePort();
//						scenePort.setNetworkId(modeList.get(i).getRouterNetworkId());
//						scenePort.setFixedIp(modeList.get(i).getRouterIp());
//						scenePortService.save(scenePort);
//
//						sceneRouterService.routerPortSave(modeList.get(i).getEnvId(),scenePort.getId(),modeList.get(i).getRouterIp());
//
//
//
//					}
//					if(modeList.get(i).getRelateModeLeft()!=null&&modeList.get(i).getRelateModeLeft().getType()==5)
//					{
//						if(modeList.get(i).getRelateModeLeft().getRelateModeLeft()!=null&&modeList.get(i).getRelateModeLeft().getRelateModeLeft().getType()==1)
//						{
//							logger.debug("dingh===添加网关:" + modeList.get(i).getRelateModeLeft().getRelateModeLeft().getPublicNetwork());
//							SceneRouter sceneRouter=sceneRouterService.get(modeList.get(i).getEnvId());
//							sceneRouter.setNetworkId(modeList.get(i).getRelateModeLeft().getRelateModeLeft().getPublicNetwork());
//							sceneRouterService.save(sceneRouter);
//						}
//					}
//					if(modeList.get(i).getRelateModeRight()!=null&&modeList.get(i).getRelateModeRight().getEnvId()!=null)
//					{
//						sceneNetwork.setId(modeList.get(i).getRelateModeRight().getEnvId());
//						List<SceneSubnet> sceneSubnetList=sceneSubnetService.findSubnetListByNetworkId(sceneNetwork);
//
//						for(int j=0;j<sceneSubnetList.size();j++)
//						{
//							logger.debug("dingh===路由增加接口:" );
//							SceneSubnet sceneSubnet=sceneSubnetList.get(j);
//							List<SceneSubnet> routerSubnetList=sceneSubnetService.findRouterSubnet(modeList.get(i).getEnvId(), sceneSubnet.getId());
//							if (routerSubnetList.size()==0)
//								sceneRouterService.saveInterface(modeList.get(i).getEnvId(), sceneSubnet.getId());
//
//						}
//					}
					logger.debug("dingh===case2:" + modeList.get(i).getEnvId());
					List<Mode> list=modeList.get(i).getList();
					SceneNetwork sceneNetwork=new SceneNetwork();
					if(list!=null&&list.size()>0)
					{
						for(int j=0;j<list.size();j++)
						{
							Mode mode=list.get(j);
							if(mode.getType()==1)
							{
								logger.debug("dingh===添加网关:" + mode.getPublicNetwork());
								SceneRouter sceneRouter=sceneRouterService.get(modeList.get(i).getEnvId());
								sceneRouter.setNetworkId(mode.getPublicNetwork());
								sceneRouterService.save(sceneRouter);
							}
							if(mode.getType()==2) {
								SceneSubnet sceneSubnet = new SceneSubnet();
								sceneSubnet.setSubnetName("snet-"+modeList.get(i).getRouterName());
								sceneSubnet.setIpVersion("4");
								String ip=modeList.get(i).getRouterIp();
								logger.debug("dingh===ip:" + ip);
								String cidr=ip.substring(0, ip.lastIndexOf("."))+".0/24";
								sceneSubnet.setCidr(cidr);
								sceneSubnet.setNetworkId(modeList.get(i).getRouterNetworkId());
								sceneSubnetService.save(sceneSubnet);

								//保存端口
								ScenePort scenePort=new ScenePort();
								scenePort.setNetworkId(modeList.get(i).getRouterNetworkId());
								scenePort.setFixedIp(modeList.get(i).getRouterIp());
								scenePortService.save(scenePort);

								sceneRouterService.routerPortSave(modeList.get(i).getEnvId(),scenePort.getId(),modeList.get(i).getRouterIp());


							}
							if(mode.getType()==3)
							{
								sceneNetwork.setId(mode.getEnvId());
								List<SceneSubnet> sceneSubnetList=sceneSubnetService.findSubnetListByNetworkId(sceneNetwork);

								for(int k=0;k<sceneSubnetList.size();k++)
								{
									logger.debug("dingh===路由增加接口:" );
									SceneSubnet sceneSubnet=sceneSubnetList.get(k);
									List<SceneSubnet> routerSubnetList=sceneSubnetService.findRouterSubnet(modeList.get(i).getEnvId(), sceneSubnet.getId());
									if (routerSubnetList.size()==0)
										sceneRouterService.saveInterface(modeList.get(i).getEnvId(), sceneSubnet.getId());

								}
							}
							if(mode.getType()==5) {
								if(mode.getList()!=null)
								{

									for(int k=0;k<mode.getList().size();k++)
									{
										Mode mode1=mode.getList().get(k);
										if(mode1.getType()==1)
										{
											logger.debug("dingh===添加网关:" + mode1.getPublicNetwork());
											SceneRouter sceneRouter=sceneRouterService.get(modeList.get(i).getEnvId());
											sceneRouter.setNetworkId(mode1.getPublicNetwork());
											sceneRouterService.save(sceneRouter);
										}
										if(mode1.getType()==3)
										{
											sceneNetwork.setId(mode1.getEnvId());
											List<SceneSubnet> sceneSubnetList=sceneSubnetService.findSubnetListByNetworkId(sceneNetwork);
											logger.debug("dingh===路由增加接口:" );
											SceneSubnet sceneSubnet=sceneSubnetList.get(0);
											List<SceneSubnet> routerSubnetList=sceneSubnetService.findRouterSubnet(modeList.get(i).getEnvId(), sceneSubnet.getId());
											if (routerSubnetList.size()==0)
												sceneRouterService.saveInterface(modeList.get(i).getEnvId(), sceneSubnet.getId());
										}
									}
								}
							}
						}
					}
					sceneCtfEnvironmentService.evmRouterInsert(sceneCtfEnvironment.getId(), modeList.get(i).getEnvId());
					break;
				case 3:
					logger.debug("dingh===case3:" + modeList.get(i).getEnvId());
					sceneCtfEnvironmentService.evmNetworkInsert(sceneCtfEnvironment.getId(), modeList.get(i).getEnvId());

					break;
				case 4:
					logger.debug("dingh===vm虚拟机:");
					logger.debug("dingh===case4:" + modeList.get(i).getEnvId());
					//保存端口

					list=modeList.get(i).getList();
					if(list!=null&&list.size()>0) {
						for (int j = 0; j < list.size(); j++) {
							Mode mode = list.get(j);
							if (mode.getType() == 3) {
								ScenePort scenePort=new ScenePort();
								scenePort.setNetworkId(mode.getEnvId());
								scenePort.setFixedIp(modeList.get(i).getVmIp());
								scenePortService.save(scenePort);
								sceneVmTemplateService.vmNetworkInsert(modeList.get(i).getEnvId(), mode.getEnvId(), sceneCtfEnvironment.getId());
								sceneCtfEnvironmentService.evmVmInsert(sceneCtfEnvironment.getId(), modeList.get(i).getEnvId(),modeList.get(i).getIsOperateMachine(),scenePort.getId(),modeList.get(i).getVmName());


							}
							if(mode.getType() == 5)
							{
								if(mode.getList()!=null)
								{

									for(int k=0;k<mode.getList().size();k++)
									{
										Mode mode1=mode.getList().get(k);
										if (mode1.getType()==3)
										{
											ScenePort scenePort=new ScenePort();
											scenePort.setNetworkId(mode.getEnvId());
											scenePort.setFixedIp(modeList.get(i).getVmIp());
											scenePortService.save(scenePort);
											sceneVmTemplateService.vmNetworkInsert(modeList.get(i).getEnvId(), mode1.getEnvId(), sceneCtfEnvironment.getId());
											sceneCtfEnvironmentService.evmVmInsert(sceneCtfEnvironment.getId(), modeList.get(i).getEnvId(),modeList.get(i).getIsOperateMachine(),scenePort.getId(),modeList.get(i).getVmName());


										}
									}
								}
							}
						}
					}else {
						if(modeList.size()==1)
						{
							sceneCtfEnvironmentService.evmVmInsert(sceneCtfEnvironment.getId(), modeList.get(i).getEnvId(),modeList.get(i).getIsOperateMachine(),modeList.get(i).getVmIp(),modeList.get(i).getVmName());
						}
					}
//					logger.debug("dingh===vm虚拟机:");
//					logger.debug("dingh===case4:" + modeList.get(i).getEnvId());
//					//保存端口
//
//					ScenePort scenePort=new ScenePort();
//					scenePort.setNetworkId(modeList.get(i).getRelateModeLeft().getEnvId());
//					scenePort.setFixedIp(modeList.get(i).getVmIp());
//					scenePortService.save(scenePort);
//
//					sceneVmTemplateService.vmNetworkInsert(modeList.get(i).getEnvId(), modeList.get(i).getRelateModeLeft().getEnvId(),sceneCtfEnvironment.getId());
//					sceneCtfEnvironmentService.evmVmInsert(sceneCtfEnvironment.getId(), modeList.get(i).getEnvId(),modeList.get(i).getIsOperateMachine(),scenePort.getId(),modeList.get(i).getVmName());

					break;
				case 5:
					logger.debug("dingh===case5:" + modeList.get(i).getEnvId());
					list=modeList.get(i).getList();
					if(list!=null&&list.size()>0) {
						for (int j = 0; j < list.size(); j++) {
							Mode mode = list.get(j);
							if (mode.getType() == 2) {
								sceneRouterService.routerFirewallInsert(modeList.get(i).getEnvId(), mode.getEnvId());
							}
						}
					}

//					sceneRouterService.routerFirewallInsert(modeList.get(i).getEnvId(),modeList.get(i).getRelateModeRight().getEnvId());
//					sceneEnvironmentService.evmSgInsert(sceneEnvironment.getId(), modeList.get(i).getEnvId());

					break;
			}
		}
		jsonModel.setSuccess(true);
		jsonModel.setDataObj(sceneCtfEnvironment.getId());
		return jsonModel;



	}

	/**
	 * 创建ctf实例
	 * @param ids
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "createCtfInstance")
	public String createCtfInstance(@RequestParam(required = false) String ids) throws Exception{
//		SceneEnvironmentInstance sceneEnvironmentInstance=new SceneEnvironmentInstance();
//		List<SceneVmTemplate> vmUrlList=new ArrayList<>();
//		sceneEnvironmentService.createInstance(sceneEnvironment, sceneEnvironmentInstance, vmUrlList);


		logger.debug("createCtfInstance==="+ids);

		SceneCtfEnvironmentInstance sceneCtfEnvironmentInstance=new SceneCtfEnvironmentInstance();



		SceneCtfEnvironment sceneCtfEnvironment=sceneCtfEnvironmentService.get(ids);
		System.err.println("1===========" + sceneCtfEnvironment.toString());

		sceneCtfEnvironmentInstance.setAutoDelete(SceneConstants.AUTO_DELETE_YES);

		System.err.println( SceneConstants.AUTO_DELETE_YES + " =========2===========" + sceneCtfEnvironmentInstance.toString());

		sceneCtfEnvironmentService.createCtfInstance(sceneCtfEnvironment, sceneCtfEnvironmentInstance);

		return null;
	}

	/**
	 * ctf实验详情
	 * @param sceneCtfEnvironment
	 * @param model
	 * @return
	 */
	@RequiresPermissions("scene:sceneCtfEnvironment:view")
	@RequestMapping(value = "detail")
	public String detail(SceneCtfEnvironment sceneCtfEnvironment, Model model) {
		List<SceneNetwork> sceneNetworkList=sceneNetworkService.findEnvironmentNetworkDetail(DelFlag.DEL_FLAG_NORMAL,sceneCtfEnvironment.getId());
//		List<SceneNetwork> sceneNetworkList=sceneNetworkService.findNetworkListByEnvironmentId(DelFlag.DEL_FLAG_NORMAL,sceneCtfEnvironment.getId());
		List<SceneRouter> sceneRouterList=sceneRouterService.findRouterListByEnvironmentId(DelFlag.DEL_FLAG_NORMAL,sceneCtfEnvironment.getId());
		List<SceneVmTemplate> sceneVmTemplateList=sceneVmTemplateService.findVMListByEnvironmentId(DelFlag.DEL_FLAG_NORMAL,sceneCtfEnvironment.getId());

		for(int i=0;i<sceneNetworkList.size();i++)
		{
			SceneSubnet sceneSubnet=new SceneSubnet();
			sceneSubnet.setNetworkId(sceneNetworkList.get(i).getId());
			List<SceneSubnet> sceneSubnet1=sceneSubnetService.findList(sceneSubnet);
			sceneNetworkList.get(i).setSubnetName(sceneSubnet1.get(0).getSubnetName());
			sceneNetworkList.get(i).setCidr(sceneSubnet1.get(0).getCidr());


		}
		for(int i=0;i<sceneRouterList.size();i++)
		{

			SceneSubnet sceneSubnet=new SceneSubnet();
			sceneSubnet.setRouterId(sceneRouterList.get(i).getId());
			List<SceneSubnet> sceneSubnet1=sceneSubnetService.getSubnetListByRouterId(sceneSubnet);
			if(sceneSubnet1.size()>0) {
				sceneRouterList.get(i).setSubnetName(sceneSubnet1.get(0).getSubnetName());
				sceneRouterList.get(i).setCidr(sceneSubnet1.get(0).getCidr());
			}

		}
//		for(int i=0;i<sceneVmTemplateList.size();i++)
//		{
//			SceneVmType type=sceneVmTypeService.get(sceneVmTemplateList.get(i).getFlavorRef());
//			sceneVmTemplateList.get(i).setRam(type.getRam());
//			sceneVmTemplateList.get(i).setVcpus(type.getVcpus());
//			sceneVmTemplateList.get(i).setDisk(type.getDisk());
//			sceneVmTemplateList.get(i).setVmTypeName(type.getName());
////			ScenePort scenePort=scenePortService.get(sceneVmTemplateList.get(i).getPortId());
////			sceneVmTemplateList.get(i).setPortId(scenePort.getFixedIp());
//
//		}
		model.addAttribute("sceneNetworkList", sceneNetworkList);
		model.addAttribute("sceneRouterList", sceneRouterList);
		model.addAttribute("sceneVmTemplateList", sceneVmTemplateList);

		model.addAttribute("sceneCtfEnvironment", sceneCtfEnvironment);
		return "modules/scene/sceneCtfEnvironmentDetail";
	}
}